package Simulation;

import IA.Menu;
import IA.MenuItem;
import IA.Service;
import java.util.ArrayList;

/**
 *
 * @author Jeremy
 */
public class OrderSimulator {

    private static OrderSimulator instance = null;
    private OrderStrategy _os;
    private static final int[] DEFAULT_ORDER_SIZES = {1, 2, 3, 4};
    private static final int[] DEFAULT_ORDER_PROBABILITIES = {10, 40, 30, 20};
    private WeightedRandParam OrderSizeProbability;

    private OrderSimulator() {
        _os = OrderSimulator.GenericOrderStrategyInstance();
        OrderSizeProbability = new WeightedRandParam(DEFAULT_ORDER_SIZES, DEFAULT_ORDER_PROBABILITIES);
    }

    public static OrderSimulator getInstance() {
        if (instance == null) {
            instance = new OrderSimulator();
        }
        return instance;
    }

    public ArrayList<MenuItem> createOrders(Service s, Menu m) {
        //list of all orders in party
        ArrayList<MenuItem> PartyOrders = new ArrayList<MenuItem>();
        for (int i = 0; i < s.getNumCustomers(); i++) {
            //number of items a customer will order
            int NumOrders = OrderSizeProbability.generateValue();
            for (int j = 0; j < NumOrders; j++) {
                PartyOrders.add(_os.generateOrder(m));
            }
        }
        return PartyOrders;
    }

    public void SetOrderSizeProbability(ArrayList<Integer> Sizes, ArrayList<Integer> Probabilities) {
        OrderSizeProbability = new WeightedRandParam(Sizes, Probabilities);
    }

    public void SetStrategy(OrderStrategy os) {
        _os = os;
    }

    public static OrderStrategy GenericOrderStrategyInstance() {
        return new GenericOrderStrategy();
    }

    public static OrderStrategy PriceBasedOrderStrategyInstance() {
        return new PriceBasedOrderStrategy();
    }
}

class GenericOrderStrategy implements OrderStrategy {

    @Override
    //randomly return an equally probable menu item
    public MenuItem generateOrder(Menu m) {
        int index = new RandParam(0, m.Size() - 1).IntValue();
        return m.getList().get(index);
    }
}

class PriceBasedOrderStrategy implements OrderStrategy {

    @Override
    public MenuItem generateOrder(Menu m) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}